﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Bxas.Utility.Cookie
{

    public class UserCookies
    {
        public static void read_cookie(string cookieName, ref string value)
        {
            //if (HttpContext.Current.Request.Cookies.AllKeys.Contains(cookieName))
            //    throw new Exception("Bu isimde cookie mevcut");

            if (HttpContext.Current.Request.Cookies[cookieName] != null)
                value = HttpContext.Current.Request.Cookies[cookieName].Value;
            else
                value = String.Empty;
        }

        public static void remove_cookie(string cookieName)
        {
            try
            {
                HttpCookie ck = HttpContext.Current.Request.Cookies[cookieName];

                HttpContext.Current.Request.Cookies.Remove(cookieName);

                ck.Expires = DateTime.Now.AddDays(-10);
                ck.Value = null;

                HttpContext.Current.Response.SetCookie(ck);
            }
            catch { }
        }

        public static void add_cookie(string cookieName, string value, int expireDateCount)
        {
            HttpCookie ck = new HttpCookie(cookieName, value);
            ck.Expires = DateTime.Now.AddDays(expireDateCount);
            HttpContext.Current.Response.Cookies.Add(ck);
        }
    }
}